package com.autobet.services.thread;

import com.autobet.dao.CommonDao;
import com.autobet.model.table.ResultHis;
import com.autobet.services.BetService;
import com.autobet.services.EnvConfigService;
import com.autobet.services.ResultService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 *
 */
public class CheckResultThread extends Thread {

    private static final Logger log = LoggerFactory.getLogger(CheckSystemThread.class);
    private long lSleepTime = 180000L;

    public CheckResultThread() {

    }

    @Override
    public void run() {
        ResultService resultService = (ResultService) EnvConfigService.getApplicationContext().getBean(ResultService.class);
        BetService betService = (BetService) EnvConfigService.getApplicationContext().getBean(BetService.class);
        CommonDao commonDao = (CommonDao) EnvConfigService.getApplicationContext().getBean(CommonDao.class);
        long var3 = 0L;

        while ("RUNING".equals(EnvConfigService.getTaskStatus())) {
            try {
                /*数据校验*/
                resultService.addInfo("数据校验开始");
                List<ResultHis> allList = resultService.getCurrentAllResultRetry(6);
                commonDao.saveOrUpdateResultHis(allList);
                resultService.addInfo("数据校验结束");
            } catch (Exception var8) {
                ;
            }

            try {
                resultService.getMgr();
            } catch (Exception var7) {
                ;
            }

            try {
                Thread.sleep(this.lSleepTime);
            } catch (InterruptedException var6) {
                betService.stopBetForException("[系统预警]系统监控结果线程异常，请暂停系统，重新执行下单!");
                log.info("[系统预警]系统监控解国线程异常，请暂停系统，重新执行下单!");
                return;
            }
        }

        log.info("系统执行状态不正确，退出[系统结果检查任务]");
        resultService.addInfo("系统执行状态不正确，退出[系统结果检查任务]，请重新启动");
    }

}
